#include "CreateRegionAction.hpp"

CreateRegionAction::CreateRegionAction(EditorRegionManager* regionManager, RegionPanel* panel, int x, int y, int w, int h){
    region.x = x;
    region.y = y;
    region.w = w;
    region.h = h;

    regionPanel = panel;
    manager = regionManager;
    desc = "Created Region";
    perform();
}

void CreateRegionAction::perform(){
    createdRegion = manager->createRegion("untitled");
    createdRegion->setArea(region.x, region.y, region.w, region.h);
    createdRegion->width = region.w;
    createdRegion->height = region.h;
    region.i = createdRegion->index;
    
    regionPanel->addRegion((EditorRegion*)createdRegion);
}   

void CreateRegionAction::undo(){
    regionPanel->removeRegion((EditorRegion*)createdRegion);
    manager->destroyRegion(region.i);
    createdRegion = 0;
}